#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# PASTED.PY                    -- by Dr. ZhuoQing 2020-09-08
#
# Note:
#============================================================

from head import *

#------------------------------------------------------------
insertstr = ''
datalinelength = 80



#------------------------------------------------------------
if len(sys.argv) > 1:
    datapaste = clipboard.paste()
    headstr = '%s = ('%sys.argv[1]

    datastr = [s for s in datapaste.split(' ') if len(s) > 0]


    headspace = len(headstr)-1
    insertstr = insertstr + headstr

    appendstr = ''
    firstlineflag = headspace

    for id,d in enumerate(datastr):
        appendstr = appendstr + '%s,'%d

        if len(appendstr) + firstlineflag >= datalinelength:
            insertstr = insertstr + appendstr
            if id < len(datastr) - 1:
                insertstr = insertstr + '\r\n'
#                insertstr = insertstr + '\\\r\n'
                appendstr = ' ' * headspace
                firstlineflag = 0
            else: appendstr = ''

    insertstr = insertstr + appendstr + ')\r\n'

    clipboard.copy(insertstr)
    tsppasteclipboard()

    exit()



#------------------------------------------------------------
pastr = [s for s in clipboard.paste().split('\r\n') if len(s) > 0]

for s in pastr:
#    printf(pastr)

    ss = s.split('=')
    if len(ss) < 2: continue

    datastr = [s for s in ss[1].strip('[]').split(',') if len(s) > 0]

    headstr = '%s = ('%ss[0]
    headspace = len(headstr)-1
    insertstr = insertstr + headstr

    appendstr = ''
    firstlineflag = headspace

    for id,d in enumerate(datastr):
        appendstr = appendstr + '%s,'%d

        if len(appendstr) + firstlineflag >= datalinelength:
            insertstr = insertstr + appendstr
            if id < len(datastr) - 1:
#                insertstr = insertstr + '\\\r\n'
                insertstr = insertstr + '\r\n'
                appendstr = ' ' * headspace
                firstlineflag = 0
            else: appendstr = ''

    insertstr = insertstr + appendstr + ')\r\n'

#------------------------------------------------------------
clipboard.copy(insertstr)
tsppasteclipboard()


printf('\a')





#------------------------------------------------------------
#        END OF FILE : PASTED.PY
#============================================================
